package com.wave.olap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oracle.olapi.metadata.mdm.MdmObject;

public abstract class OlapBean<K,T> {

	public OlapBean() {
		olapData = new HashMap<MultiDimensionalKey<K>, T>();
		dimensionData = new HashMap<MdmObject, List<OlapTableObject>>(); 
	}
	
	protected Map<MultiDimensionalKey<K>, T> olapData;
	protected List<MdmObject> dimension;
	protected Map<MdmObject, List<OlapTableObject>> dimensionData;
	
	public T getData(ArrayList<K> axis) {
		MultiDimensionalKey<K> key = new MultiDimensionalKey<K>(axis);	
		if (olapData.get(key) == null)
			return null;
		return olapData.get(key);
	}
	
	public void add(MultiDimensionalKey<K> k, T value) {
		olapData.put(k, value);
	}
	public List<OlapTableObject> getDim(Integer i) {
		if (i >= dimension.size() || dimensionData.get(dimension.get(i)) == null)
			return new ArrayList<OlapTableObject>();
		return dimensionData.get(dimension.get(i));
	}
	public void setDimensionMetadata(List<MdmObject> dim,  List<List<OlapTableObject> > data) {
		this.dimension = dim;
		for (int i = 0; i < dimension.size(); i++)
			dimensionData.put(dimension.get(i), data.get(i));
	}
}
